package com.data.security;

import com.data.security.modelo.ControlPin;
import com.data.security.modelo.Preferencias;
import com.data.security.modelo.sebastian.ShaCrypt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CambioActivity extends Activity {

	private EditText uno, dos, tres, cuatro;
	private ControlPin pin;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actividad_cambio);
		cargarViews();
		pin = new ControlPin(this, uno, dos, tres, cuatro);

	}

	public void cambiarpass(View view) {

		String pass = pin.getText();
		if (!pass.trim().equals("") && pass.trim().length()==4) {
			byte[] clave = ShaCrypt.generarArreglo(pass.getBytes(),
					ShaCrypt.SHA256);
			pass = Base64
					.encodeToString(clave, 0, clave.length, Base64.NO_WRAP);
			Log.d("pass", pass);
			Preferencias.setClave(getApplicationContext(), pass);
			startActivity(new Intent(getApplicationContext(),
					InicioActivity.class));
			finish();
		}else{
			Toast.makeText(getApplicationContext(), getString(R.string.passvacio), Toast.LENGTH_LONG).show();
		}
	}

	private void cargarViews() {

		uno = (EditText) findViewById(R.id.cambio_password1);
		dos = (EditText) findViewById(R.id.cambio_password2);
		tres = (EditText) findViewById(R.id.cambio_password3);
		cuatro = (EditText) findViewById(R.id.cambio_password4);

	}
	
	@Override
	public void onPause(){
		super.onPause();
		this.finish();
	
	}

}
